package com.ximu.sharenet;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class NETReceiver extends BroadcastReceiver {
	private boolean can = false;
    @Override
    public void onReceive(Context context, Intent intent) {
    	Log.i("my","网络变更");
    	//WIFI
    	if(isAble("192.168.43.8")){
            new ExeCMD(ShellManage.SET_NET_WIFI, new CallBack() {
    			@Override
    			void run(String out, String error, String exc) {
    				Log.i("my",out+error+exc);
    			}
    		}).start();
    		return;
    	}
    	//USB
    	if(isAble("192.168.42.8")){
            new ExeCMD(ShellManage.SET_NET_USB, new CallBack() {
    			@Override
    			void run(String out, String error, String exc) {
    				Log.i("my",out+error+exc);
    			}
    		}).start();
    		return;
    	}
    }
    
    /**
     * 检测是否可连通
     */
    private boolean isAble(String ip){
		new ExeCMD(ShellManage.UTIL_PING+ip, new CallBack() {
			@Override
			void run(String out, String error, String exc) {
				if(out.indexOf("rtt") != -1){
					can = true;
				}else{
					can = false;
				}
			}
		}).exe();
		return can;
    }
}
